package cn.edu.cuit.aumalls.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import com.github.pagehelper.PageInfo;

import cn.edu.cuit.aumalls.constant.PageConstant;
import cn.edu.cuit.aumalls.entity.Goods;
import cn.edu.cuit.aumalls.entity.GoodsType;
import cn.edu.cuit.aumalls.service.FindGoodsService;
import cn.edu.cuit.aumalls.service.GoodsTypeService;

@Controller
public class FindGoodsByNameController {
	
	@Autowired
	private FindGoodsService findGoodsService;
	@Autowired
	private GoodsTypeService goodsTypeService;

	
	@RequestMapping("/showGoodsByName")
	public String showgoods(Model model,
			@RequestParam(value = "pageNum", required = false, defaultValue = "1") int pageNum,
			@RequestParam(value = "goodsName",required = false, defaultValue = "") String goodsName) {
		
		PageInfo<Goods> goods = findGoodsService.findGoodsByname(pageNum, PageConstant.PAGE_SIZE, goodsName);
		List<GoodsType> goodsType = goodsTypeService.showlv1(); // 商品大类型
		List<GoodsType> allGoodsType = goodsTypeService.showAll(); // 显示全部商品种类
		System.out.println(goodsType);
		System.out.println(goods);
		System.out.println(allGoodsType);
		model.addAttribute("list", goods);
		model.addAttribute("goodsType", goodsType);
		model.addAttribute("allGoodsType", allGoodsType);
		
	
		return "showlist";
	}

}
